Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: OpenDoc Cookbook /
Chapter 2 - SamplePart Tutorial


SamplePart Structure

SamplePart is implemented primarily in a single C++ class, which is described in this chapter. It also uses a set of its own utility functions, collection classes, and various utilities provided with the Mac OS implementation of OpenDoc.

SamplePart System Object Model Interface

The System Object Model (SOM) is a standard object infrastructure upon which the OpenDoc component software architecture is built. All OpenDoc part editors are represented to OpenDoc by a subclass of ODPart, which is a SOM class. The interface to a SOM class is written in the SOM Interface Definition Language (IDL) and adheres to certain protocols specific to SOM.

SamplePart incorporates a scheme by which the part's SOM interface is largely hidden from the programmer. SamplePart has only one SOM class, which is a subclass of ODPart, referred to as the SOM wrapper class. This SOM class overrides all ODPart methods, although SamplePart implements only some of them. For those methods that SamplePart implements, the SOM wrapper class methods delegate the implementation to a C++ class that provides the capabilities of SamplePart.

The SOM wrapper class is named som_SamplePart, and it is defined in IDL. The SOM class methods merely call corresponding methods in the C++ class, which is named SamplePart. For ODPart methods that the SamplePart class does not implement, the SOM class override method bodies are empty. They are provided so that you can extend SamplePart simply by adding a call to a method in a C++ class--you do not need to use the SOM compiler or revise the SOM class IDL interfaces.

Generally, you can use SamplePart's SOM interface as provided in the sample code base--you don't need to understand SOM in order to understand SamplePart. For an introduction to IDL that describes SOM artifacts found in the definition of the som_SamplePart class, refer to Appendix B.

Calling Inherited Methods

For ODPart override methods that require calling the parent class implementation, the call is made in the SOM class implementation. To know whether you need to call the parent class, see the code for the som_SamplePart wrapper class (in which the inherited method calls are made) and the OpenDoc Class Reference (which explains for each method how its inherited method should be called).

SOM Wrapper Class and Part Wrapper Object

The SOM wrapper class is not the part wrapper object described in the OpenDoc Programmer's Guide for the Mac OS. The part wrapper object is a private object that OpenDoc instantiates and uses to represent the part editor. OpenDoc passes a reference to the part wrapper object to the part editor in its InitPart or InitPartFromStorage method, as described in "The InitPart Method".

SamplePart File Structure

The primary source files composing the SamplePart program are the following:

SamplePart.h SamplePart class definition
SamplePart.cpp SamplePart method implementations
SamplePartDef.h Constant definitions
SamplePartUtils.h Utility class definitions
SamplePartUtils.cpp Utility method implementations
SamplePartGlobals.h Global variables structure definition
SamplePartGlobals.cpp External global variables initialization
SamplePartVers.h Version definitions
SampleCollections.h Collection class definitions
SampleCollections.cpp Collection method implementations
SamplePart.r Resource definitions
SamplePartOtherResources.rsrc Other resources used by SamplePart
CompDefs.h Defines for compiling SamplePart

The source files for SamplePart's SOM interface are the following:

som_SamplePart.idl SOM wrapper class definition
som_SamplePart.xh SOM-emitted public headers
som_SamplePart.xih SOM-emitted private headers
som_SamplePart.cpp SOM wrapper method implementations
som_SamplePartInit.cpp CFM initialization function
som_SamplePart.exp SOM-emitted class export symbols


Previous Book Contents Book Index Next

© Apple Computer, Inc.
16 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help